﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class UserUpdate : System.Web.UI.Page
{
    LogicLayer logic = new LogicLayer();
    public static string eid;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            string name = "", deptid = "", email = "", mobile = "", salary = "";
            string sex = "", status = "";
            string ondate = "", offdate = "";
            string place = "", dname = "";
            int i;
            eid = Request.QueryString["EmployID"];


            string sqlstring = "select employee.* from employee where employee.EmployID = " +
                      eid;
            DataSet ds = logic.GetDataSet(sqlstring);

            name = ds.Tables[0].Rows[0][1].ToString();
            deptid = ds.Tables[0].Rows[0][2].ToString();
            email = ds.Tables[0].Rows[0][4].ToString();
            mobile = ds.Tables[0].Rows[0][5].ToString();
            sex = ds.Tables[0].Rows[0][6].ToString();
            status = ds.Tables[0].Rows[0][7].ToString();
            ondate = ds.Tables[0].Rows[0][8].ToString();
            offdate = ds.Tables[0].Rows[0][9].ToString();
            salary = ds.Tables[0].Rows[0][10].ToString();


            if (deptid == "1001")
            { place = "北京"; dname = "网络搜索部"; }
            else if (deptid == "1002")
            { place = "北京"; dname = "软件开发部"; }
            else if (deptid == "1003")
            { place = "北京"; dname = "人力资源部"; }
            else if (deptid == "1004")
            { place = "北京"; dname = "系统设计部"; }
            else if (deptid == "1005")
            { place = "北京"; dname = "产品研发部"; }
            else if (deptid == "1006")
            { place = "北京"; dname = "市场部"; }

            else if (deptid == "2001")
            { place = "上海"; dname = "网络搜索部"; }
            else if (deptid == "2002")
            { place = "上海"; dname = "系统设计部"; }
            else if (deptid == "2003")
            { place = "上海"; dname = "产品研发部"; }
            else if (deptid == "2004")
            { place = "上海"; dname = "市场部"; }

            else if (deptid == "3001")
            { place = "广州"; dname = "软件开发部"; }
            else if (deptid == "3002")
            { place = "广州"; dname = "产品研发部"; }
            else if (deptid == "3003")
            { place = "广州"; dname = "系统设计部"; }
            else if (deptid == "3004")
            { place = "广州"; dname = "测试部"; }

            TextBox1.Text = eid;
            TextBox2.Text = name;
            TextBox3.Text = email;
            TextBox4.Text = mobile;
            TextBox5.Text = salary;
            TextBox6.Text = ondate;
            TextBox7.Text = offdate;

            if (sex == "男")
                RadioButtonList1.Text = "帅哥";
            else
                RadioButtonList1.Text = "靓妹";

            RadioButtonList2.Text = status;

            DropDownList4.Text = place;
            DropDownList5.Text = dname;
        }
        
        this.Button1.Attributes["onclick"] = "return confirm('确定要修改吗?')";
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        string name, deptid = "", email, mobile, salary;
        string sex, status;
        string ondate, offdate;
        string place, dname;
        string later_eid;
        later_eid = TextBox1.Text.Trim().ToString();
        name = TextBox2.Text.Trim().ToString();
        email = TextBox3.Text.Trim().ToString();
        mobile = TextBox4.Text.Trim().ToString();
        salary = TextBox5.Text.Trim().ToString();

        if (RadioButtonList1.Text.Trim().ToString() == "帅哥")
            sex = "男";
        else
            sex = "女";

        status = RadioButtonList2.Text.Trim().ToString();

        ondate = TextBox6.Text.Trim().ToString();
        offdate = TextBox7.Text.Trim().ToString();

        place = DropDownList4.Text.ToString();
        dname = DropDownList5.Text.ToString();

        if (place == "北京" && dname == "网络搜索部")
            deptid = "1001";
        else if (place == "北京" && dname == "软件开发部")
            deptid = "1002";
        else if (place == "北京" && dname == "人力资源部")
            deptid = "1003";
        else if (place == "北京" && dname == "系统设计部")
            deptid = "1004";
        else if (place == "北京" && dname == "产品研发部")
            deptid = "1005";
        else if (place == "北京" && dname == "市场部")
            deptid = "1006";

        else if (place == "上海" && dname == "网络搜索部")
            deptid = "2001";
        else if (place == "上海" && dname == "系统设计部")
            deptid = "2002";
        else if (place == "上海" && dname == "产品研发部")
            deptid = "2003";
        else if (place == "上海" && dname == "市场部")
            deptid = "2004";

        else if (place == "广州" && dname == "软件开发部")
            deptid = "3001";
        else if (place == "广州" && dname == "产品研发部")
            deptid = "3002";
        else if (place == "广州" && dname == "系统设计部")
            deptid = "3003";
        else if (place == "广州" && dname == "测试部")
            deptid = "3004";




        string sqlstring = "update employee set EmployID = " + later_eid + ",EmployName = '" +
            name + "',DeptID = " + deptid + ",Email = '" + email + "',Mobile = '" + mobile +
                "',Sex = '" + sex + "',Status = '" + status + "',OnboardDate = '" +
                ondate + "',OffboardDate = '" + offdate + "',Salary = '" + salary + "'" +
               " where EmployID = " + eid;

        if (place == "北京")
            logic.ExcuteSQLStatement_BJ(sqlstring);
        else if (place == "上海")
            logic.ExcuteSQLStatement_SH(sqlstring);
        else
            logic.ExcuteSQLStatement_GZ(sqlstring);

        Response.Redirect("UserManager.aspx");




    }
}
